/*
 * Copyright 2011-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0.
 * See `LICENSE` in the project root for license information.
 */

package me.ijleex.mgmt.framework.page;

import java.sql.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author me
 */
@SuppressWarnings("serial")
public class Query extends HashMap<String, Object> {

    public Query() {
        super();
    }

    public Query(Map<String, Object> params) {
        this.putAll(params);
    }

    public Double getAsDouble(String name) {
        Object value = this.get(name);
        if (value != null) {
            return Double.parseDouble(value.toString());
        }
        return null;
    }

    public String getAsString(String name) {
        return this.get(name).toString();
    }

    public Long getAsLong(String name) {
        Object value = this.get(name);
        if (value != null) {
            return Long.parseLong(value.toString());
        }
        return null;
    }

    public Integer getAsInt(String name) {
        Object value = this.get(name);
        if (value != null) {
            return Integer.parseInt(value.toString());
        }
        return null;
    }

    public Boolean getAsBoolean(String name) {
        Object value = this.get(name);
        if (value != null) {
            return Boolean.parseBoolean(value.toString());
        }
        return null;
    }

    public java.util.Date getAsDate(String name) {
        Object value = this.get(name);
        if (value != null) {
            return Date.valueOf(value.toString());
        }
        return null;
    }

    public Object getObj(String name) {
        return this.get(name);
    }

}
